package com.yang.proxy.dynamicproxy.jdk;

import com.yang.proxy.Buyer;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * JDK自带的动态代理
 * @author yang
 * @version 0.1
 * @date 2019/4/12
 */
public class JDKProxy implements InvocationHandler {

    private Object object = null;

    public JDKProxy(Object object) {
        this.object = object;
    }

    public Object proxy() {
        return Proxy.newProxyInstance(object.getClass().getClassLoader(), object.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("寻找房源");
        Object o = method.invoke(object, args);
        System.out.println("签署合同");
        return o;
    }
}
